<?php

namespace maotool\core;

use maotool\exception\Exception;
use maotool\exception\RuntimeException;
use maotool\object\ObjUtil;
use maotool\object\ReflectionUtil;

/**
 * @method static *()
 */
class Facade
{

    /**
     * 获取Facade对应的容器
     * @return Instance|null
     */
    protected static function getFacadeContainer()
    {
        return null;
    }

    public static function __callStatic($method, $ages)
    {
        if (ObjUtil::isNotNull(static::getFacadeContainer())) {
            return ReflectionUtil::method([static::getFacadeContainer()->proxy, $method], $ages);
        } else {
            if (Container::has($method)) {
                if (ReflectionUtil::isMethod(Container::getName($method))) {
                    return ReflectionUtil::method(Container::getName($method), $ages);
                } else {
                    return Container::getName($method);
                }
            }
        }
        throw new RuntimeException("not call function");
    }

}

